package com.sense.kukoo.biz_media.adapter.provider

import android.view.View
import android.widget.TextView
import com.sense.kukoo.biz_media.R
import com.sense.kukoo.biz_media.adapter.MediaListDetailAdapter
import com.sense.kukoo.common.repo.bean.BookDetailsBean
import com.sense.kukoo.common.repo.bean.MediaListDetailItemBean
import com.sense.kukoo.common.wiget.adapter.provider.MultiItemProvider
import com.sense.kukoo.common.wiget.adapter.viewholder.BaseViewHolder

class MediaDesProvider(
    val listener: MediaListDetailAdapter.MediaListListener,
): MultiItemProvider<MediaListDetailItemBean>() {

    override fun getItemType(): Int = MediaListDetailItemBean.TYPE_MEDIA_DES

    override fun getItemLayoutId(): Int = R.layout.biz_media_item_media_des

    override fun onBindViewHolder(viewHolder: BaseViewHolder, item: MediaListDetailItemBean) {
        val data: BookDetailsBean = item.bean!!
        //
        val iv_btn_show_des = viewHolder.getView(R.id.iv_btn_show_des)
        val tv_music_des: TextView = viewHolder.getView(R.id.tv_music_collection) as TextView
        val tv_music_des_all: TextView = viewHolder.getView(R.id.tv_music_des_all) as TextView
        //
        val text = data.introduction
        //
        fun showAll(){
            tv_music_des_all.setText(text)
            tv_music_des_all.visibility = View.VISIBLE
            tv_music_des.visibility = View.GONE
            iv_btn_show_des.visibility = View.GONE
            data.isShowDes = true
        }
        if(data.isShowDes ?: false){
            showAll()
        }else{
            tv_music_des.setText(text)
            tv_music_des_all.visibility = View.GONE
            tv_music_des.visibility = View.VISIBLE
            iv_btn_show_des.visibility = View.VISIBLE
            iv_btn_show_des.setOnClickListener {
                showAll()
            }
        }
    }
}